package HomeWork;

public class Computer {
    private Screen screen;
    private String brand;

    private double price;

    //构造  alter+enter
    public Computer() {
    }

    public Computer(String brand, double price) {
        this.brand = brand;
        //this.price = price;

        //如果某个属性需要校验.. 构造方法中直接调用setter方法
        setPrice(price);
    }

    //getter/setter  alter+enter

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        //针对 价格，不能低于1000, 也不能超过20000;
        //对于超出这个值的，给一个默认值：2000
        if(price<1000 || price>20000){
            this.price = 2000;
            return;//return语句是用来结束整个方法的.下面的代码不会执行了.
        }
        this.price = price;
    }

    public Screen getScreen() {
        return screen;
    }

    public void setScreen(Screen screen) {
        this.screen = screen;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Computer{");
        sb.append("brand='").append(brand).append('\'');
        sb.append(", price=").append(price);
        sb.append('}');
        return sb.toString();
    }
}


